package com.vint.leetcode;


/*
 * 1.done easy
 * 2.七进制字符串
 */

//TODO:扩展
//任意数m的n进制数，不足补abcedf, n<=36
public class Leetcode504 {

    public String convertToBase7(int num) {
        if(num==0){
            return "0";
        }
        if(num<0){
            return "-"+convertToBase7(-num);
        }
        StringBuffer sb = new StringBuffer();
        while(num!=0){
            int mod = num % 7;
            sb.append(mod+"");
            num /= 7;
        }
        return sb.reverse().toString();

    }
    public String mConvertToBasen(int num, int n) {
        StringBuffer sb = new StringBuffer();
        while(num!=0){
            int mod = num % n;
            if(n>10){
                if(mod<10) {
                    sb.append(mod + "");
                }else{
                    char c = (char)(mod - 10 + 'a');
                    sb.append(c);
                }
            }else {
                sb.append(mod + "");
            }
            num /= n;
        }
        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        Leetcode504 leetcode551 = new Leetcode504();
        System.out.println(leetcode551.convertToBase7(-7));
        System.out.println(leetcode551.mConvertToBasen(35,36));
    }
  }
